import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

def whale_model(y, t, alpha):
    x1, x2 = y
    dx1dt = 0.05 * x1 * (1 - x1/150000) - alpha * x1 * x2
    dx2dt = 0.08 * x2 * (1 - x2/400000) - alpha * x1 * x2
    return [dx1dt, dx2dt]

def interactive_plot():
    try:
        alpha = float(input("Enter alpha value (e.g., 1e-7): "))
        initial = [5000, 7000]
        t = np.linspace(0, 200, 1000)
        solution = odeint(whale_model, initial, t, args=(alpha,))
        x1 = solution[:, 0]
        x2 = solution[:, 1]
        
        plt.figure(figsize=(10, 6))
        plt.plot(t, x1, label='Blue Whale')
        plt.plot(t, x2, label='Sperm Whale')
        plt.title(f'α = {alpha}')
        plt.xlabel('Years')
        plt.ylabel('Population')
        plt.legend()
        plt.show()
    except ValueError:
        print("Invalid input! Please enter a numeric value.")
    except Exception as e:
        print(f"An error occurred: {e}")

# 主程序入口
if __name__ == "__main__":
    print("=== Interactive Mode ===")
    interactive_plot()
